/**
 * 表单验证
 * 
 * @param {Object} rules 验证字段的规则
 * @param {Object} messages 验证字段的提示信息
 * 
 */

import basic from './basic.js';
var actmodel = new basic();
actmodel.do = "user_center"
actmodel.offset = function (that, reset, para, xcsorts) { 
  if(!xcsorts)
  {
    xcsorts=[["id", "desc"], ["createtime", "desc"]] ;
  }
 
  var acturlpara = {};   
  acturlpara["url"] = "entry/wxapp/"+actmodel.do
  if (para) {
    para["op"] = "offset"
  }
  else {
    this.wherepara["op"] = "offset"
  }
  return actmodel.pagelist(acturlpara, that, reset, para, xcsorts);
}
actmodel.coinoffset = function (that, reset, para, xcsorts) { 
  if(!xcsorts)
  {
    xcsorts=[["id", "desc"], ["createtime", "desc"]] ;
  }
 
  var acturlpara = {};   
  acturlpara["url"] = "entry/wxapp/"+actmodel.do
  if (para) {
    para["op"] = "coinoffset"
  }
  else {
    this.wherepara["op"] = "coinoffset"
  }
  return actmodel.pagelist(acturlpara, that, reset, para, xcsorts);
}
actmodel.moneyoffset = function (that, reset, para, xcsorts) { 
  if(!xcsorts)
  {
    xcsorts=[["id", "desc"], ["createtime", "desc"]] ;
  }
 
  var acturlpara = {};   
  acturlpara["url"] = "entry/wxapp/"+actmodel.do
  if (para) {
    para["op"] = "moneyoffset"
  }
  else {
    this.wherepara["op"] = "moneyoffset"
  }
  return actmodel.pagelist(acturlpara, that, reset, para, xcsorts);
}

actmodel.expoffset = function (that, reset, para, xcsorts) { 
  if(!xcsorts)
  {
    xcsorts=[["id", "desc"], ["createtime", "desc"]] ;
  }
 
  var acturlpara = {};   
  acturlpara["url"] = "entry/wxapp/"+actmodel.do
  if (para) {
    para["op"] = "expoffset"
  }
  else {
    this.wherepara["op"] = "expoffset"
  }
  return actmodel.pagelist(acturlpara, that, reset, para, xcsorts);
}
actmodel.setclub = function (clubid) {
  return new Promise((resolve) => {
    var urlpara = { do: "user_center", op: "setclub" };
    var postdata = { clubid: clubid }
    this.post(urlpara, postdata).then(res => {

      resolve(res)

    })
  })
}

actmodel.getmycloubinfo = function (clubid,lng,lat,showlast=false) {
  
  if(!clubid)
  {
    clubid=0
  }
 
  //op
  return new Promise((resolve) => {
    var urlpara = { do: "user_center", op: "mycloubinfo",clubid,lng,lat,isshowlast:showlast};
    var postdata = { }
    this.post(urlpara, postdata).then(res => {
      resolve(res)
    })
  })
}
actmodel.simplevipinfo = function () {
  return new Promise((resolve) => {
    var urlpara = { do: "user_center", op: "simplevipinfo" };
    var postdata = { }
    this.post(urlpara, postdata).then(res => {
      if(res["status"]==1){

        var app= getApp();

        if(res["obj"]&&app.globalData.member && app.globalData.member.memberinfo){

          // app.globalData.member.memberinfo["amount"]=res["obj"]["amount"]
          // app.globalData.member.memberinfo["vips"]=res["obj"]["vips"]

          app.globalData.member.memberinfo["amount"]=res["obj"]["amount"]
          app.globalData.member.memberinfo["money"]=res["obj"]["money"]
          app.globalData.member.memberinfo["score"]=res["obj"]["score"]
          app.globalData.member.memberinfo["totalmoney"]=res["obj"]["totalmoney"]
          app.globalData.member.memberinfo["vips"]=res["obj"]["vips"]
        }
    
      }
      resolve(res)
    })
  })
}

actmodel.balacerecharge = function (model) {
  return new Promise((resolve) => {
    var urlpara = { do: "user_center", op: "balacerecharge" };
    var postdata = { model: JSON.stringify(model) }
    this.post(urlpara, postdata).then(res => {
      resolve(res)
    })
  })
}

actmodel.exchange = function (value) {
  return new Promise((resolve) => {
    var urlpara = { do: "user_center", op: "exchange"};
    var postdata = { value: value }
    this.post(urlpara, postdata).then(res => {
      resolve(res)
    })
  })
}

//获取等级优惠券
actmodel.getcoupon = function (con) {
  return new Promise((resolve) => {
    var urlpara = { do: "user_center", op: "getcoupon"};
    var postdata = { condition: JSON.stringify(con)  }
    this.post(urlpara, postdata).then(res => {
      resolve(res)
    })
  })
}
//注册会员vip
actmodel.regvip = function (value) {
  return new Promise((resolve) => {
    var urlpara = { do: "user_center", op: "regvip" };
    var postdata = {value:JSON.stringify(value) }
    this.post(urlpara, postdata).then(res => {
      
      resolve(res)
    })
  })
}
//修改会员vip
actmodel.editvip = function (vipdata) {
  return new Promise((resolve) => {
    var urlpara = { do: "user_center", op: "editvip" };
    var postdata = {vipdata:JSON.stringify(vipdata) }
    this.post(urlpara, postdata).then(res => {
      
      resolve(res)
    })
  })
}
//获取会员等级产品
actmodel.gradeoffset = function (that, reset, para, xcsorts) { 
  if(!xcsorts)
  {
    xcsorts=[["id", "desc"], ["createtime", "desc"]] ;
  }
 
  var acturlpara = {};   
  acturlpara["url"] = "entry/wxapp/"+actmodel.do
  if (para) {
    para["op"] = "gradeoffset"
  }
  else {
    this.wherepara["op"] = "gradeoffset"
  }
  return actmodel.pagelist(acturlpara, that, reset, para, xcsorts);
}
//获取会员二维码
actmodel.getqrcode = function () {
  return new Promise((resolve) => {
    var urlpara = { do: "user_center", op: "getqrcode" };
    var postdata = {}
    this.post(urlpara, postdata).then(res => {
      
      resolve(res)
    })
  })
}

//获取易货小程序码
actmodel.getyihuoqrcode = function (price) {
  return new Promise((resolve) => {
    var urlpara = { do: "user_center", op: "getyihuoqrcode",price:price };
    var postdata = {}
    this.post(urlpara, postdata).then(res => {
      
      resolve(res)
    })
  })
}
actmodel.vipinfo = function () {
  return new Promise((resolve) => {
    var urlpara = { do: "user_center", op: "vipinfo" };
    var postdata = { }
    this.post(urlpara, postdata).then(res => {
      
      resolve(res)
    })
  })
}
actmodel.getmember=function(uid){
  var app = getApp();
  var data = { "op": "getmember", uid }
  return new Promise((resolve, reject) => {
    app.util.request({
      'url': 'entry/wxapp/'+actmodel.do,
      'data': data,
      'method': "get",
      showLoading: false,
      success: function (res) {
        if (res.data.errno == 0) {
          resolve(res.data.data);
        }
        reject(res.data.message);
      },
      fail: function (res) {
        reject(((res.data && res.data.message) ? res.data.message : res.errMsg));
      },
      complete: function () {
      }
    });
  });
}
module.exports = actmodel;